package xworker.javafx.control;

import javafx.scene.control.ComboBoxBase;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.javafx.beans.property.PropertyFactory;
import xworker.javafx.util.JavaFXUtils;

public class ComboBoxBaseActions {
    static{
        PropertyFactory.regist(ComboBoxBase.class, "valueProperty", o -> {
            ComboBoxBase<?> obj = (ComboBoxBase<?>) o;
            return obj.valueProperty();
        });
        PropertyFactory.regist(ComboBoxBase.class, "promptTextProperty", o -> {
            ComboBoxBase<?> obj = (ComboBoxBase<?>) o;
            return obj.promptTextProperty();
        });
        PropertyFactory.regist(ComboBoxBase.class, "onShownProperty", o -> {
            ComboBoxBase<?> obj = (ComboBoxBase<?>) o;
            return obj.onShownProperty();
        });
        PropertyFactory.regist(ComboBoxBase.class, "onShowingProperty", o -> {
            ComboBoxBase<?> obj = (ComboBoxBase<?>) o;
            return obj.onShowingProperty();
        });
        PropertyFactory.regist(ComboBoxBase.class, "onHiddenProperty", o -> {
            ComboBoxBase<?> obj = (ComboBoxBase<?>) o;
            return obj.onHiddenProperty();
        });
        PropertyFactory.regist(ComboBoxBase.class, "onHidingProperty", o -> {
            ComboBoxBase<?> obj = (ComboBoxBase<?>) o;
            return obj.onHidingProperty();
        });
        PropertyFactory.regist(ComboBoxBase.class, "armedProperty", o -> {
            ComboBoxBase<?> obj = (ComboBoxBase<?>) o;
            return obj.armedProperty();
        });
        PropertyFactory.regist(ComboBoxBase.class, "editableProperty", o -> {
            ComboBoxBase<?> obj = (ComboBoxBase<?>) o;
            return obj.editableProperty();
        });
        PropertyFactory.regist(ComboBoxBase.class, "onActionProperty", o -> {
            ComboBoxBase<?> obj = (ComboBoxBase<?>) o;
            return obj.onActionProperty();
        });
    }

	public static void init(ComboBoxBase<?> base, Thing thing, ActionContext actionContext) {
		ControlActions.init(base, thing, actionContext);
		
        if(thing.valueExists("editable")){
            base.setEditable(thing.getBoolean("editable"));
        }
        if(thing.valueExists("promptText")){
            String promptText = JavaFXUtils.getString(thing, "promptText", actionContext);
            if(promptText != null) {
                base.setPromptText(promptText);
            }
        }
	}
}
